import axios from 'axios'

const instance = axios.create({
  // baseURL: 'localhost:8080'
  // baseURL: 'http://localhost:8080'
})

instance.interceptors.request.use(function (config) {
  if (localStorage.token) { // 判断token是否存在
    config.headers.token = localStorage.token // 将token设置成请求头
    // config.headers.Authorization = `Bearer ${localStorage.token}`
  }
  return config
}, function (error) {
  return Promise.reject(error)
})

instance.interceptors.response.use(function (response) {
  return response.data
}, function (error) {
  return Promise.reject(error)
})

export default instance
